﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class orgman_methods_modi : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            MasApp.BLL.Check.CheckLogin();
        }
        if (ViewState["rowCount"] == null)
        {
            addTable();
            ViewState["rowCount"] = Convert.ToInt16(ViewState["rowCount"]) + 1;
            Label2.Text = Convert.ToString(ViewState["rowCount"]) + "个";
        }
        else
        {
            for (int i = 0; i < Convert.ToInt16(ViewState["rowCount"]); i++)
            {
                addTable();
            }
        }
    }
    protected void addTable()
    {
        TableRow tr;
        TableCell tc;
        TextBox tb;

        tr = new TableRow();

        tc = new TableCell();
        Label lb = new Label();
        lb.Text = Table1.Rows.Count.ToString();
        tc.Controls.Add(lb);
        tr.Cells.Add(tc);

        tc = new TableCell();
        tb = new TextBox();
        tb.ID = "tb_levelname" + Table1.Rows.Count.ToString();
        tc.Controls.Add(tb);
        tr.Cells.Add(tc);

        tc = new TableCell();
        tb = new TextBox();
        tb.ID = "tb_judgement" + Table1.Rows.Count.ToString();
        tc.Controls.Add(tb);
        tr.Cells.Add(tc);

        tc = new TableCell();
        tb = new TextBox();
        tb.ID = "tb_value" + Table1.Rows.Count.ToString();
        tc.Controls.Add(tb);
        tr.Cells.Add(tc);

        Table1.Rows.Add(tr);
    }

    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        if (Table1.Rows.Count < 11)
        {
            addTable();

            ViewState["rowCount"] = Convert.ToInt16(ViewState["rowCount"]) + 1;
            Label2.Text = Convert.ToString(ViewState["rowCount"]) + "个";
        }
        else
        {
            Label2.Text = "最多10个";
        }
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        if (Table1.Rows.Count > 2)
        {
            Table1.Rows.RemoveAt(Table1.Rows.Count - 1);
            ViewState["rowCount"] = Convert.ToInt16(ViewState["rowCount"]) - 1;
            Label2.Text = Convert.ToString(ViewState["rowCount"]) + "个";
        }
        else
        {
            Label2.Text = "最少1个";
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Request["methodid"] == null)
        {
            MasApp.BLL.ResponseHelper.alert("非法操作", "review.aspx");            
        }
        else
        {
            bool bo = true;
            for (int i = 1; i < Table1.Rows.Count; i++)
            {
                string tb_levelname = Request["tb_levelname" + i.ToString()].ToString();
                string tb_judgement = Request["tb_judgement" + i.ToString()].ToString();
                string tb_value = Request["tb_value" + i.ToString()].ToString();
                if (tb_levelname == "" || tb_judgement == "" || tb_value == "")
                {
                    bo = false;
                    //app.BLL.response.alert("请填写完整信息！");
                    Label2.Text = "请填写完整信息！";
                    break;
                }
                else
                {
                    float result;
                    bo = float.TryParse(tb_value, out result);
                    if (!bo)
                    {
                        //app.BLL.response.alert("请检查分值是否有非 数字 字符！");
                        Label2.Text = "请检查分值是否有非 数字 字符！";
                        break;
                    }
                }
            }
            bool bo2 = true;
            if (bo)
            {
                for (int i = 1; i < Table1.Rows.Count; i++)
                {
                    string tb_levelname = Request["tb_levelname" + i.ToString()].ToString();
                    string tb_judgement = Request["tb_judgement" + i.ToString()].ToString();
                    string tb_value = Request["tb_value" + i.ToString()].ToString();

                    MasApp.Model.level lev = new MasApp.Model.level();
                    lev.Judgement = tb_judgement;
                    lev.Levelname = tb_levelname;
                    lev.Methodid = int.Parse(Request["methodid"].ToString());
                    lev.Levelvalue = Convert.ToSingle(tb_value);
                    bo2 = MasApp.BLL.reg.AddLevel(lev);
                }
            }
            else
            {
                bo2 = false;
            }
            if (bo2)
            {
                Label2.Text="添加成功!";
                //Server.Transfer(Request.Url.ToString());
                //Response.Redirect(Request.Url.ToString());
                Table1.Rows.Clear();
                ViewState["rowCount"] = null;
            }
            else
            {
                Label2.Text = "操作失败~";
            }
        }
    }

}
